<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      xmlns:th="http://www.thymeleaf.org"
      layout:decorator="backstage/layout">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>广告管理</title>
</head>

<body>
<div id="content" layout:fragment="content">
    <script type="text/javascript">

		function paging(page){
		    $("[name=page]").val(page);
		    $("#searchForm").submit();
		}
        $(function(){
        	$(".btn-danger").click(function(e){
                if(confirm("确定删除吗?"))
                {
                    $.ajax({
                        url:'/tadvert/delete.json?id='+ e.currentTarget.id,
                        type:'POST',
                        dataType:"json",
                        success:function(date) {
                            if(date.obj){
                                $(".close").click();
                                alert("删除成功！");
                                window.location.href = "/tadvert/list.htm";
                            }else{
                               alert("删除有误！");
                                window.location.href = "/tadvert/list.htm";
                            }
                        }
                    });
                }
            }); 
                  
        	//编辑
            $('.editLanguageBT').click(function(e){
                e.preventDefault();               
                var id=e.currentTarget.id;
                window.location.href = "/tadvert/getById.htm?id="+id;
                
            });

            //添加
            $(".btn-setting").click(function(e){
            	e.preventDefault();    
            	window.location.href = "/tadvert/getById.htm?";
            })                       
            
            $(".btn-inverse").click(function(e){
                $("#page").attr("value","1");
            })
            var options = {
                    currentPage: $("[name=page]").val(),
                    totalPages: $("[name=totalPage]").val(),
                    alignment:"left",
                    itemTexts: function (type, page, current) {
                        switch (type) {
                            case "first":
                                return "首页";
                            case "prev":
                                return "上一页";
                            case "next":
                                return "下一页";
                            case "last":
                                return "末页";
                            case "page":
                                return page;
                        }
                    },
                    pageUrl: function(type,page,current){
                        return "javascript:paging('"+page+"');";
                    }
                }
                $('#example').bootstrapPaginator(options);
             
        });
    </script>
    <div class="box-content">
        <div class="row-fluid sortable">
            <div class="box span12">
                <h3 class="row-fluid header smaller lighter blue">
                   <span class="label label-large label-pink arrowed-right">广告管理</span>
                </h3>
                <!-- <h3 class="row-fluid header smaller lighter blue" style="border:none;">
                    <a href="#" class="btn btn-small btn-success btn-setting"><i class="icon-user"></i>新建广告</a>
                </h3> -->
                
                <form action="/tadvert/list.htm" method="post" id="searchForm" style="margin-left:10px;">
		            <input type="hidden"  id="page" name="page" th:value="${page.page}" />
		            <input type="hidden"  name="totalPage" th:value="${page.totalPage}" />		            
		            	<span class="topword">标题：</span>
		            	<input type="text" class="input-xlarge focused" name="title" th:value="${advert.title}"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		            	<span class="topword">状态：</span>
		            			<select name="status" id="status">
		            				<option value="">全部</option>
		            				<option value="1" th:selected="${advert.status == 1}">启用</option>
		            				<option value="2" th:selected="${advert.status == 2}">关闭</option>
		            			</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		            <input type="submit" class="btn btn-info btn-inverse tpbtn" value="搜索"/>				
		        </form>
        
                <div class="box-content">
                    <table class="table table-striped table-bordered bootstrap-datatable datatable">
                        <thead>
                        <tr >                           
                            <th style="text-align: center;">序号</th>
                            <!-- <th style="text-align: center;">广告位名称</th> -->
                            <th style="text-align: center;">标题</th>
                            <th style="text-align: center;">图片</th>
                            <th style="text-align: center;">广告指向地址</th>
                            <th style="text-align: center;">广告状态</th>
                            <th style="text-align: center;">创建时间</th>
                            <th style="text-align: center;">操作管理</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="advert:${page.result}">
                        	<td th:text="${advert.id}" style="text-align: center;"></td>
                        	<!-- <td th:text="${advert.name}" style="text-align: center;"></td> -->
                            <td th:text="${advert.title}" style="text-align: center;"></td>
                            <td style="text-align: center;">
                            	<img th:src="${advert.advertImg}" style="height: 120px;width:120px;" />
                            </td>
                            <td th:text="${advert.advertUrl}" style="text-align: center;width:120px;"></td>
                            <td  style="text-align: center;">
                              <span th:if="${advert.status == 1}">开启</span>
                              <span th:if="${advert.status == 2}">关闭</span>                             
                            </td>
                            <td th:text="${advert.createTime}" style="text-align: center;"></td>
                            <td style="text-align: center;">
                                 <a class="deletebtn btn btn-small btn-danger" th:id="${advert.id}" style="width: 26px;">
                                    		删除                                   
                                </a> 
                                 <a class="editbtn btn btn-info btn-small editLanguageBT" th:id="${advert.id}" style="width: 26px;">                                  
                           					 编辑                                                                                                                     
                                </a>                                                                
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div style="margin-bottom: 0px; margin-left: auto;margin-right: auto">
		                <div id="example" style="margin-bottom:0px"></div>
		            </div>
                </div>
            </div><!--/span-->
        </div><!--/row-->
    </div>
</div>
</body>
</html>
